package com.sfzd5.noipinfo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

public class SubmissionExpandableListAdapter extends BaseExpandableListAdapter {

    private Context context;
    private LayoutInflater inflater;
    SubmissionResult result;

    public SubmissionExpandableListAdapter(Context context, SubmissionResult result){
        this.context = context;
        this.result = result;
        this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getGroupCount() {
        return result.data.size();
    }

    @Override
    public int getChildrenCount(int i) {
        return result.data.get(i).ps.size();
    }

    @Override
    public Object getGroup(int i) {
        return result.data.get(i).ps;
    }

    @Override
    public Object getChild(int i, int i1) {
        return result.data.get(i).ps.get(i1);
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    //android.R.layout.simple_list_item_1
    @Override
    public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
        TextView groupView = (TextView) inflater.inflate(android.R.layout.simple_expandable_list_item_1  ,null);
        groupView.setText(result.data.get(i).h);
        return groupView;
    }

    @Override
    public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
        View childView = inflater.inflate(android.R.layout.simple_expandable_list_item_2  ,null);
        TextView text1 = childView.findViewById(android.R.id.text1);
        TextView text2 = childView.findViewById(android.R.id.text2);
        SubmissionResult.Submission s = result.data.get(i).ps.get(i1);
        text1.setText(s.title);
        text2.setText(s.submission);
        return childView ;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return false;
    }
}
